<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button onclick="change()">更改</button>
    <div class="box">
      <div class="div-1">div-1</div>
      <div id="test" class="test">test</div>
    </div>
    <style>
      .box {
        padding: 10px;
        box-shadow: 0 0 1px red;
        display: flex;
      }
      .div-1 {
        width: 50%;
        box-shadow: 0 0 1px red;
        padding: 10px;
        resize: both;
        overflow: hidden;
      }
      .test {
        /* flex-grow: 1; */
        box-shadow: 0 0 1px red;
        padding: 10px;
        margin: 10px;
        resize: both;
        /* width: 50px;
        height: 50px; */
        word-break: break-all;
        overflow: auto;
      }
    </style>
    <script>
      function change() {
        let el = document.querySelector("#test");
        // el.style.width =Math.floor(Math.random()* 1000) + 'px';
        // el.style.height = Math.floor(Math.random() * 1000) + "px";
        el.innerHTML = new Array(Math.floor(Math.random() * 50))
          .fill("z")
          .map((it, i) => i + "a")
          .join("");
      }
      window.onload = function () {
        // 尺寸监听
        const resizeObserver = new ResizeObserver((entries) => {
          console.count("resize变化啦");
        });
        const someEl = document.querySelector("#test");
        resizeObserver.observe(someEl);
      };
    </script>
  </body>
</html>
